package cn.pku.sirx.snad.uias.analyzer.similarity;

import org.springframework.util.Assert;

import cn.pku.sirx.snad.uias.dao.IHometownDao;
import cn.pku.sirx.snad.uias.model.entity.HomeTown;
import cn.pku.sirx.snad.uias.model.entity.SiteUser;

/**
 * @author WangXiao
 */
public class AreaAnalyzer implements ISimilarityAnalyzer {

	@Override
	public int analyze(SiteUser fromUser, SiteUser toUser) {
		Assert.notNull(fromUser);
		Assert.notNull(toUser);

		HomeTown fromHometown = hometownDao.getByUserId(fromUser.getId());
		HomeTown toHometown = hometownDao.getByUserId(toUser.getId());
		if (fromHometown.getCity() != null) {
			if (fromHometown.getCity().equals(toHometown.getCity())) {
				return 3;
			}
			if (fromHometown.getProvince().equals(toHometown.getProvince())) {
				return 2;
			}
		}
		return 0;
	}

	private IHometownDao hometownDao;

	public void setHometownDao(IHometownDao hometownDao) {
		this.hometownDao = hometownDao;
	}

}
